<?php

namespace app\admin\model;

use think\Model;


class TeacherClass extends Model
{

    

    

    // 表名
    protected $name = 'teacher_class';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text'
    ];

    public function getPeriodSetList()
    {
        return ['1' => __('Period_set 1'),'2' => __('Period_set 2')];
    }
    
    public function getStatusList()
    {
        return ['1' => __('Status 1'),'2' => __('Status 2'),'3' => __('Status 3')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function teacher(){
        return $this->hasOne(User::class, 'id', 'teacher_id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
    }
    public function teachers()
    {
        return $this->hasOne(User::class, 'id', 'teacher_id', [], 'LEFT')->field('id,avatar,mobile,username,nickname');
    }

    public function users()
    {
        return $this->hasOne(User::class, 'id', 'user_id', [], 'LEFT')->field('id,avatar,mobile,username,nickname');
    }

    public function dtls(){
        return $this->hasMany(TeacherClassDtl::class, 'teacher_class_id', 'id')->where(['is_xs'=>1]);
    }

    public function address(){
        return $this->hasOne(ClassAddress::class,'id','address_id');
    }
}
